package com.jie.erp.springbootjieerp.controller;


import com.jie.erp.springbootjieerp.bean.JepUser;
import com.jie.erp.springbootjieerp.service.JepUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {



    @Autowired
    JepUserService jepUserService;



    @PostMapping("/user/login")
    public String login(String username, String password, Model model, HttpSession session){
        JepUser jepUser = jepUserService.selectByUserAndPass(username, password);
        if (null==jepUser){
            model.addAttribute("msg","用户名或命名错误!");
            return "login";
        }else {
            session.setAttribute("user",jepUser);
            return "redirect:/main.html";
        }
    }

}
